using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class changeonclick : MonoBehaviour
{
	private Ray ray;

	private RaycastHit hit;

	//按键改为按钮
	private bool Ebool;
	public Image text;
	private bool isloading;
	private float time;

	public void OnPointerEnter()
	{
		if (time >= 0.7f)
		{
			time = 0;
			Ebool = true;
		}
	}

	public void OnPointerExit()
	{
		text.gameObject.SetActive(false);
		Ebool = false;
	}

	private void Update()
	{
		time += Time.deltaTime;
		//发射一条射线，在检测到窗户之后直接通关
		if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out var hitInfo, 20))
		{
			if (hitInfo.transform.name == "ExitWindow")
			{
				text.gameObject.SetActive(true);
                if (Ebool && !isloading)//防止重复跳场景
                {
	                isloading = true;
                    SceneManager.LoadScene("farmanight");
                }
			}
        }
        else
        {
            text.gameObject.SetActive(false);
        }
	}
}
